import 'package:device_preview/device_preview.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:uikit/theme/riki_base_theme.dart';
import 'package:uikit/uikit.dart';
import 'package:uikit_example/pages/demo/register/page/login_page.dart';
import 'package:uikit_example/pages/demo/register/page/register_page.dart';
import 'package:uikit_example/pages/my_home_page.dart';

class RikiUiKitApp extends StatelessWidget {
  final bool preview;
  final DevicePreviewData? previewSettings;

  const RikiUiKitApp({
    Key? key,
    this.preview = false,
    this.previewSettings,
  }) : super(key: key);

  static Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
    ...standardsRoutes,
    ...widgetRoutes,
    ...utilRoutes,
  };

  static Map<String, WidgetBuilder> standardsRoutes = <String, WidgetBuilder>{
    '/Register': _build(const RegisterPage()),
    '/Login': _build(const LoginPage()),
    //'/AppBar': _build(const AppBarPage()),
    // '/Badge': _build(const BadgePage()),
    // '/BottomPicker': _build(const BottomPickerPage()),
    // '/BottomSheet': _build(const BottomSheetPage()),
    // '/Button': _build(const ButtonPage()),
    // '/CheckBox': _build(const CheckBoxPage()),
    // '/CheckboxGroup': _build(const CheckBoxGroupPage()),
    // '/CityPicker': _build(const CityPickerPage()),
    // '/Countdown': _build(const CountdownPage()),
    // '/DatePicker': _build(const DatePickerPage()),
    //'/Dialog': _build(const DialogPage()),
    //'/Empty': _build(const EmptyPage()),
    // '/Icons': _build(const IconsPage()),
    // '/Notice': _build(const NoticePage()),
    // '/Radio': _build(const RadioPage()),
    // '/Rate': _build(const RatePage()),
    // '/RollPicker': _build(const RollPickerPage()),
    // '/Skeleton': _build(const SkeletonPage()),
    // '/Sort': _build(const SortPage()),
    // '/Switch': _build(const SwitchPage()),
    // '/Stepper': _build(const StepperPage()),
    // '/TabBar': _build(const TabBarPage()),
    // '/Toast': _build(const ToastPage()),
  };

  static Map<String, WidgetBuilder> widgetRoutes = <String, WidgetBuilder>{
    // '/AnimBottomNav': _build(const AnimBottomNavPage()),
    // '/Dropdown': _build(const DropdownPage()),
    // '/Picker': _build(const PickerPage()),
    // '/Calendar': _build(const CalendarPage()),
    // '/Price': _build(const PricePage()),
    // '/Shape': _build(const ShapePage()),
    // '/TextField': _build(const TextFieldPage()),
    // '/svgaLoading': _build(const SvgLoadingPage()),
    // '/Trend': _build(const TrendPage()),
    // '/Banner': _build(const BannerPage()),
    // '/Label': _build(const LabelPage()),
    // '/ExpandableText': _build(const ExpandableTextPage()),
    // '/IndexBarList': _build(const IndexBarListPage()),
    // '/GifImage': _build(const GifImagePage()),
    // '/AnchorImage': _build(const AnchorImagePage()),
  };

  static Map<String, WidgetBuilder> utilRoutes = <String, WidgetBuilder>{
    // '/Debounce Throttle': _build(const DebounceAndThrottlePage()),
    // '/Screenshot': _build(const ScreenshotPage()),
  };

  @override
  Widget build(BuildContext context) {
    return RikiUikit.init(
      context: context,
      builder: (BuildContext ctx, RikiBaseTheme theme) {
        return MaterialApp(
          title: 'Riki Uikit',
          theme: theme.theme,
          debugShowCheckedModeBanner: !preview,
          useInheritedMediaQuery: preview,
          locale: preview ? DevicePreview.locale(context) : null,
          builder: preview ? DevicePreview.appBuilder : null,
          home: const MyHomePage(),
          // 国际化支持
          localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          supportedLocales: const <Locale>[
            Locale('zh', 'CN'),
            Locale('en', 'US'),
          ],
          routes: routes,
        );
      },
    );
    return DevicePreview(
        enabled: preview,
        data: previewSettings ??
            const DevicePreviewData(
              settings: DevicePreviewSettingsData(
                backgroundTheme: DevicePreviewBackgroundThemeData.dark,
                toolbarPosition: DevicePreviewToolBarPositionData.right,
              ),
            ),
        builder: (_) {
          return RikiUikit.init(
            context: context,
            builder: (BuildContext ctx, RikiBaseTheme theme) {
              return MaterialApp(
                title: 'Riki Uikit',
                theme: theme.theme,
                debugShowCheckedModeBanner: !preview,
                useInheritedMediaQuery: preview,
                locale: preview ? DevicePreview.locale(context) : null,
                builder: preview ? DevicePreview.appBuilder : null,
                home: const MyHomePage(),
                // 国际化支持
                localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                  GlobalCupertinoLocalizations.delegate,
                ],
                supportedLocales: const <Locale>[
                  Locale('zh', 'CN'),
                  Locale('en', 'US'),
                ],
                //routes: routes,
              );
            },
          );
        });
  }

  static WidgetBuilder _build(Widget widget) {
    return (_) {
      return widget;
    };
  }
}
